import {
  cardRank
} from '../../apis/group'
const app = getApp();

Page({
  data: {
    list: []
  },

  onLoad(options) {
    this.setData({
      ...options
    });
  },
  onShow() {
    this.getCardWall(this.data.groupId);
  },

  getCardWall(id) {
    cardRank(id).then(res => {
      if (res.data.code === 200) {
        let {
          data
        } = res.data;
        data.forEach(v => {
          if (!new RegExp('https://').test(v.avatar) && !new RegExp('http://').test(v.avatar)) v.avatar = app.globalData.url + v.avatar;
        });
        this.setData({
          list: data
        });
      };
    });
  },

  previewCard(e) {
    let {
      index
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/groupCardPreview/index?type=cardWall&groupId=${this.data.groupId}&current=${index}&cardId=${this.data.list[index].cardId}`
    });
  }
})